package io.renren.modules.oa.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.oa.dao.DeptUserDao;
import io.renren.modules.oa.entity.DeptUserEntity;
import io.renren.modules.oa.service.DeptUserService;


@Service("deptUserService")
public class DeptUserServiceImpl extends ServiceImpl<DeptUserDao, DeptUserEntity> implements DeptUserService {

    @Autowired
    private DeptUserDao deptUserDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String userName = (String) params.get("userName");
        String deptId = (String) params.get("deptId");
        String[] deptIdArr = deptId.split(",");
        params.put("deptIdArr", deptIdArr);
//        IPage<DeptUserEntity> page = this.page(
//                new Query<DeptUserEntity>().getPage(params),
//                new QueryWrapper<DeptUserEntity>()
//                        .like(StringUtils.isNotBlank(userName), "user_name", userName)
//                        .in(StringUtils.isNotBlank(deptId), "dept_id", deptIdArr)
//        );

        IPage<DeptUserEntity> iPage = new Page<>(Long.parseLong((String)params.get("page")), Long.parseLong((String)params.get("limit")));
        IPage<DeptUserEntity> page2 = deptUserDao.queryListByCondition(iPage, params);

//        return new PageUtils(page);
        return new PageUtils(page2);
    }

    @Override
    public DeptUserEntity queryById(Long userId) {
        return deptUserDao.queryById(userId);
    }

}